import 'package:erp_widget/src/theme/index.dart';
import 'package:erp_widget/src/utils/screen/index.dart';
import 'package:flutter/material.dart';

/// 带子标题的文本
class DxSubTitle extends StatelessWidget {
  /// 一级标题
  final String? title;
  final TextStyle? titleStyle;
  final Widget? titleWidget;

  /// 子标题
  final String? subTitle;
  final TextStyle? subTitleStyle;
  final Widget? subTitleWidget;

  /// 内容排列的方向，可选值为 `horizontal` `vertical`
  final Axis direction;

  /// 间距
  final double space;

  const DxSubTitle({
    Key? key,
    this.title,
    this.titleStyle,
    this.titleWidget,
    this.subTitle,
    this.subTitleStyle,
    this.subTitleWidget,
    this.direction = Axis.horizontal,
    this.space = 5,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return direction == Axis.horizontal
        ? Row(
            crossAxisAlignment: CrossAxisAlignment.end,
            children: [
              titleWidget ?? Text(title ?? '', style: titleStyle ?? DxStyle.$404040$14),
              SizedBox(width: space.sp),
              subTitleWidget ?? Text(subTitle ?? '', style: subTitleStyle ?? DxStyle.$999999$12),
            ],
          )
        : Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              titleWidget ?? Text(title ?? '', style: titleStyle ?? DxStyle.$404040$14),
              SizedBox(height: space.sp),
              subTitleWidget ?? Text(subTitle ?? '', style: subTitleStyle ?? DxStyle.$999999$12),
            ],
          );
  }
}
